/*!
    \copyright  Copyright (c) 2023 Qualcomm Technologies International, Ltd.\n
                All Rights Reserved.\n
                Qualcomm Technologies International, Ltd. Confidential and Proprietary.
    \file
    \addtogroup   sensor_subsystem
    @{
    \brief      Private interfaces for managing the sensor subsystem.

*/

#ifndef SENSOR_SUBSYSTEM_PRIVATE_H_
#define SENSOR_SUBSYSTEM_PRIVATE_H_

#include "sensor_subsystem.h"
#include "panic.h"
#include "task_list.h"
#include "app/message/system_message.h"

/*! Sensor subsystem transport is not immediately available after the
    sensor subsystem has started. This delay is used to inform the
    system when completed.
 */
#define sensorSubsystemConnectedDelayMs() 100


typedef enum 
{
    SENSOR_SUBSYS_STATE_UNINITIALISED,
    SENSOR_SUBSYS_STATE_OFF,
    SENSOR_SUBSYS_STATE_STARTING,
    SENSOR_SUBSYS_STATE_STARTED,
} sensor_subsystem_state_t;


/*! \brief Events sent by the sensor subsystem module */
typedef enum
{
    /*! Requested sensor subsystem image has been loaded successfully 
        This should be used as a trigger to initialise any remote
        procedure calls required
     */
    SENSOR_SUBSYSTEM_INTERNAL_START_SS = INTERNAL_MESSAGE_BASE,

#ifndef MESSAGE_SENSOR_SS_COMMS_STATUS
    /*! Timer used when starting the sensor subsystem. Communication
        is not immediately possible. The timer gives an indication 
        of when this may be.

        This is not required once MESSAGE_SENSOR_SS_COMMS_STATUS
        is available.
     */
    SENSOR_SUBSYSTEM_INTERNAL_COMMS_DELAY_TIMER,
#endif
} sensor_subsystem_internal_msg_t;


/*! Date for the CAA sensor subsystem module */
typedef struct
{
    /*! Current state */
    sensor_subsystem_state_t    state;
    /*! List of registered clients */
    task_list_t                *clients;
    /*! File to be used when loading sensor subsystem */
    FILE_INDEX                  file_id;
    /*! Flags affecting startup of sensor subsystem, see sensor_ss.h */
    uint32                      sensor_startup_flags;
#ifndef MESSAGE_SENSOR_SS_COMMS_STATUS
    /*! A timer is currently used to decide when the sensor subsystem
        can be used. This flag is set when the timer expires */
    bool                        ready_timer_expired;
#endif
    /*! Task to send a SENSOR_SUBSYSTEM_STARTED_IND to, when the sensor
        subsystem has started successfully */
    Task                        init_task;
} sensor_subsystem_data_t;

void sensorSubsystem_setState(sensor_subsystem_state_t state);
sensor_subsystem_state_t sensorSubsystem_getState(void);

void sensorSubsystem_resetInternalState(void);

#endif /* SENSOR_SUBSYSTEM_PRIVATE_H_ */
/*! @} */